package org.learn.intermediate.homework;

public class HomeWork01 {
    public static void main(String[] args) {
        Person person = new Person("李毅", 18, "律师");
        Person person1 = new Person("张三", 25, "老师");
        Person person2 = new Person("李华", 40, "护士");
        Person[] people = {person,person1,person2};
        //输出当前对象数组
        for (int i = 0; i < people.length; i++) {
            System.out.println(people[i]);
        }
        //使用冒泡排序

        Person temp = null;
        for( int i =0; i < people.length - 1; i++){ //外层循环
            for( int j = 0;j < people.length - 1 - i;j++){
                if(people[j].getAge() > people[j+1].getAge()){
                    temp = people[j];
                    people[j] = people[j+1];
                    people[j+1] = temp;
                }
                }
            }
        System.out.println("排序后的效果");
        for (int i = 0; i < people.length; i++) {
            System.out.println(people[i]);

        }



    }
}
class Person{
    private String name = " ";
    private int age = 0;
    private String job = " ";

    public Person(String name, int age, String job) {
        this.name = name;
        this.age = age;
        this.job = job;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getJob() {
        return job;
    }

    public void setJob(String job) {
        this.job = job;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", job='" + job + '\'' +
                '}';
    }
}